package com.lei.lib_croe.http.factory;

import com.lei.lib_croe.http.product.NetWorkProduct;

import retrofit2.Retrofit;

public class RetrofitFactory implements IRetrofitFactory {

    private static RetrofitFactory retrofitFactory;
    private NetWorkProduct netWorkProduct;

    public static RetrofitFactory getInstance() {
        if (retrofitFactory == null) {
            retrofitFactory = new RetrofitFactory();
        }
        return retrofitFactory;
    }

    public static Retrofit RetrofitHttp() {
        return getInstance().createRetrofit(RetrofiType.NETWORK).getRerofit();
    }

    @Override
    public NetWorkProduct createRetrofit(RetrofiType type) {
        switch (type) {
            case UPLOAD:
                if (netWorkProduct == null) {
                    netWorkProduct = new NetWorkProduct();
                }
                return netWorkProduct;
            case NETWORK:
                if (netWorkProduct == null) {
                    netWorkProduct = new NetWorkProduct();
                }
                return netWorkProduct;
            default:
                if (netWorkProduct == null) {
                    netWorkProduct = new NetWorkProduct();
                }
                return netWorkProduct;
        }
    }
}
